/**
 * 计算新开页面宽度和左偏移量
 */
var $contentWscan = $('.menu_right').width(),
	$menuLeftWscan = $('.menu_left').outerWidth();
localStorage.setItem('$contentWscan', $contentWscan);
localStorage.setItem('$menuLeftWscan', $menuLeftWscan);
//console.log($menuLeftWscan)

//mui初始化
mui.init();
var status = ''; // 登录状态
var subpages = ['scanMsg.html', 'scanSupervision.html', 'scanLevel.html', 'scanPenalize.html'];
var subpage_style = {
	width: $contentWscan,
	left: $menuLeftWscan,
	bottom: '0px'

};
var aniShow = {},
	index = 0;
//创建子页面，首个选项卡页面显示，其它均隐藏；
mui.plusReady(function() {
	var current = plus.webview.currentWebview(),
		id = current.rid;
		scanbacks = current.backs;
	//console.log(scanbacks)
	var extras = { // 传递参数
		backs:scanbacks,
		//rid:20171010452088
		//rid:20171011470595
		//rid:20171031676360
		rid: id
	}
	var self = plus.webview.currentWebview();
	for(var i = 0; i < 4; i++) {
		var temp = {};
		var nwaiting = plus.nativeUI.showWaiting();
		var sub = plus.webview.create(subpages[i], subpages[i], subpage_style, extras);
		if(i > 0) {
			sub.hide();
		} else {
			temp[subpages[i]] = "true";
			mui.extend(aniShow, temp);
		}
		self.append(sub);
	}
});
//当前激活选项
var activeTab = subpages[index];
//console.log(activeTab)
//选项卡点击事件
mui('.menu_nav').on('tap', 'a', function(e) {
	var targetTab = this.getAttribute('href'),
		home = plus.webview.currentWebview();
	home.show()

	//mui.toast('当前点击是的:' + targetTab)
	$('.item').removeClass('active')
	$(this).parent().addClass('active')
	//console.log(targetTab)
	if(targetTab == activeTab) {
		return;
	}

	//显示目标选项卡
	//若为iOS平台或非首次显示，则直接显示
	if(mui.os.ios || aniShow[targetTab]) {
		plus.webview.show(targetTab);
	} else {
		//否则，使用fade-in动画，且保存变量
		var temp = {};
		temp[targetTab] = "true";
		mui.extend(aniShow, temp);
		plus.webview.show(targetTab, "auto", 300);
	}
	//隐藏当前;
	plus.webview.hide(activeTab);
	//更改当前活跃的选项卡
	activeTab = targetTab;
});